package renshi.utils;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
/**
 * �����ȡ��Դ�ļ���������ݿ���ز���
 * */

public class DBUtils {
      private static String url;
      private static String userName;
      private static String pwd;
      /**
       * ʹ�þ�̬����г�ʼ������
       */
      static{
    	   url="jdbc:mysql://localhost/person";
 /*   	   userName=ConfigUtils.getDBValue("username");
    	   pwd=ConfigUtils.getDBValue("pwd");*/
 /*          try{
        	    //ע����
        	    DriverManager.registerDriver(new com.microsoft.sqlserver.jdbc.SQLServerDriver());
           }catch(SQLException ex){
        	   ex.printStackTrace();
           }*/
      }
      /**
  	 * getConnection��̬�������ڴ����Դ��ȡConnection����
     * @throws ClassNotFoundException 
  	 */
  	public static Connection getConnection() throws SQLException, ClassNotFoundException {
  		Class.forName("org.gjt.mm.mysql.Driver");
  		Connection con = DriverManager.getConnection(url, "root","root");
  		return con;
  	}

  	/**
  	 * closeCon�������ڹر���������ݿ������صĶ���
  	 */
  	public static void CloseCon(Connection con) throws SQLException {
  		if (con != null) { // �ر���ݿ�l�Ӷ���
  			con.close();
  		}
  	}

  	/**
  	 * closeStmt�������ڹر�����ִ�ж���
  	 */
  	public static void CloseStmt(Statement stmt) throws SQLException {
  		if (stmt != null) { // �ر�����ִ�ж���
  			stmt.close();
  			stmt = null;
  		}
  	}

  	/**
  	 * CloseRs
  	 * �رս�����
  	 */
  	public static void CloseRs(ResultSet rs) throws SQLException {
  		if (rs != null) { // �رս�����
  			rs.close();
  			rs = null;
  		}
  	}
    
}